// 区域热力
class areaHeat {
  constructor() {
    this.materialMap = new Map();
    this.disposeList = new Array();
  }
  create(e) {
    // this.context.curAreaHeat
  }
  onRefresh2() {
    var config = this.config.custom;
    var { diff, min } = this.getExtremum();
    var nullColor = this.createMaterial(config.nullColor);
    this.disposeList.push(nullColor);
    var h = new Qs.b(config.colorRange);
    var mapData = new Map();
    this.props.data.forEach(item => {
      mapData.set(String(item.adcode), item);
    });
    this.context.curMap.blockMap.forEach(block => {
      var n;
      var a = mapData.get(t.adcode);
      if (a) {
        var color = null;
        if ('连续映射' == config.colorType) {
          var p = (a.value - min) / diff;
          color = h.get(p);
        } else {
          for (var m = 0; m < config.colorList.length; m++) {
            var v = config.colorList[m];
            if (a.value >= v.range.min && a.value <= v.range.max) {
              color = v.color;
              break;
            }
          }
        }
        if (color) {
          this.disposeList.push(this.createMaterial(color));
        } else {
          n = nullColor;
        }
      } else {
        n = nullColor;
      }
      this.materialMap.set(block.adcode, n);
      block.setTopSurfaceMaterial(n);
    });
  }
  getMaterial(id) {
    return this.materialMap.get(id);
  }
  createMaterial(e) {
    var t;
    if (this.context.materialPool.get('topSurface')) {
      t = this.context.materialPool.get('topSurface');
    } else {
      t = new us();
    }
    return t.clone();
  }
  dispose() {
    this.disposeList.forEach(i => {
      i.dispose();
    });
  }
  onDestroy() {
    this.context.curMap.blockMap.forEach(i => {
      i.resetTopSurface();
    });
    this.context.curAreaHeat = null;
  }
  getExtremum() {
    var data = this.props.data;
    if (!data.length) {
      return { diff: null, min: null };
    }
    var max = data[0].value;
    var min = data[0].value;
    data.forEach(i => {
      max = Math.max(max, i.value);
      min = Math.min(min, i.value);
    });
    return { diff: max - min, min };
  }
}
// 信息面板
class infoPanel {
  constructor() {
    this.timer = 0;
    this.carouselInterval = 0;
    this.carouselEnable = false;
    this.carouselIndex = -1;
    this.carouselPaused = false;
  }
  getAssetsListMap() {
    var e = this.config.content.statusBgList;
    var t = {
      HTMLImageElement: []
    };
    Object.values(e).forEach(function (e) {
      t.HTMLImageElement.push(e.dot.normal.img, e.dot.select.img, e.src);
    });
    return t;
  }
  onRefresh() {
    var p = [];
    var t = this.props.data;
    var a = this.context.curMap;
    var i = a.coordTransform;
    var r = a.blockMap;
    var o = this.config;
    var s = o.content;
    var l = o.interactAnimation;
    this.carouselInterval = 1e3 * l.interval;
    this.carouselEnable = l.carouselEnable;
    var u = new Map();
    var c = Object.values(s.statusBgList);
    c.forEach(function (e) {
      u.set(e.status, e);
    });
    var h = c[0];
    if (h.status) p = [];
    t.forEach(function (t, n) {
      var a = u.get(t.status || h);
      if (a) {
        var o = i.toWorld(t, []);
        var s = Object(d.a)(o, 2);
        var l = s[0];
        var c = s[1];
        if (l && c) {
          p.push({
            i: n,
            x: l,
            y: c,
            data: t,
            config: e.config,
            context: e,
            id: n,
            bgConfig: a,
            blockMap: r
          });
        }
      }
    });
    this.itemList.refresh(p, {
      ref: ['context', 'bgConfig'],
      deep: ['data', 'config']
    });
  }
  dispose() {
    this.itemList.clear();
  }
  setSelectedItem(e) {
    this.itemList.list.forEach(function (t) {
      t.selected = t.props.i == e;
    });
    this.timer = 0;
    this.carouselIndex = e;
  }
  onUpdate(e) {
    if (
      this.carouselEnable &&
      this.itemList.list.length > 0 &&
      !this.carouselPaused &&
      this.timer >= this.carouselInterval
    ) {
      this.carouselNext();
      this.timer += e;
    }
  }
  carouselNext() {
    var e = (this.carouselIndex + 1) % this.itemList.list.length;
    this.setSelectedItem(e);
  }
}
// 粒子系统
class particleSystem {
  constructor() {
    this.particleList = [];
    this.emitRate = 0;
    this.emitTime = 0;
    this.maxCount = 0;
    this.emitAreaRotateMatrix = null;
    this.geometry = new Kt();
    this.particleMaterial = null;
    this.instancedMesh = null;
    this.planeGeometry = new Un(1, 1);
  }
  onRefresh() {
    var e = this.config;
    var t = e.basic;
    var n = e.emit;
    var a = n.rate;
    var i = n.area;
    this.onDestroy();
    this.emitRate = a / 1e3;
    this.maxCount = t.maxCount;
    this.emitAreaRotateMatrix = new Qe();
    this.emitAreaRotateMatrix.makeRotationFromEuler(i.rotate.x, i.rotate.y, i.rotate.z);
    var r = t.transform;
    var o = r.translate;
    var s = r.rotation;
    var l = r.scale;
    this.position.set(o.x, o.y, o.z);
    this.rotation.set(Object(Qs.m)(s.x), Object(Qs.m)(s.y), Object(Qs.m)(s.z));
    this.scale.set(l.x, l.y, l.z);
    var u = this.context.assetsMgr.getTextureImage(t.texture);
    var c = new me(u);
    c.needsUpdate = true;
    var h = new ls({
      uniforms: {
        map: {
          value: c
        }
      },
      vertexShader:
        '\nprecision highp float;\nuniform mat4 modelViewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat3 normalMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 modelMatrix;\n\nattribute mat4 instanceMatrix;\nattribute vec3 instanceColor;\nattribute vec3 position;\nattribute vec2 uv;\nattribute float opacity;\n\nvarying vec3 vColor;\nvarying vec2 vUv;\nvarying float vOpacity;\n\nvoid main() {\n    vUv = uv;\n    vColor = instanceColor;\n    vOpacity=opacity;\n\n    mat4 resetMatrix=mat4(viewMatrix*modelMatrix*instanceMatrix);\n\n    resetMatrix[0][0] = instanceMatrix[0][0]; \n    resetMatrix[0][1] = 0.0; \n    resetMatrix[0][2] = 0.0; \n\n    resetMatrix[1][0] = 0.0; \n    resetMatrix[1][1] = instanceMatrix[1][1]; \n    resetMatrix[1][2] = 0.0; \n\n    resetMatrix[2][0] = 0.0; \n    resetMatrix[2][1] = 0.0; \n    resetMatrix[2][2] = instanceMatrix[2][2];\n\n    gl_Position = projectionMatrix * resetMatrix * vec4( position, 1.0 );\n}\n',
      fragmentShader:
        '\nprecision highp float;\nuniform sampler2D map;\nvarying vec2 vUv;\nvarying vec3 vColor;\nvarying float vOpacity;\n\nvoid main() {\n    vec4 diffuseColor = texture2D( map, vUv );\n    gl_FragColor = diffuseColor*(vColor,vOpacity);\n    gl_FragColor*=vec4(vColor,vOpacity);\n}\n',
      blending: 2,
      depthTest: false,
      transparent: true
    });
    this.disposeList.push(h);
    this.particleMaterial = h;
  }
  onDestroy() {
    this.clear(), this.geometry.dispose(), this.planeGeometry.dispose(), (this.particleList = []);
  }
  getAssetsListMap() {
    return {
      HTMLImageElement: [this.config.basic.texture]
    };
  }
  emit() {
    var e = this.config;
    var t = e.basic;
    var n = t.lifeTime;
    var a = (t.start, t.end, e.emit.area);
    var i = vc(a.x);
    var r = vc(a.y);
    var o = vc(a.z);
    if ('球形' == a.shape) {
      var s = Math.random() * Math.PI * 2;
      var l = Math.random() * Math.PI;
      i = i * Math.sin(l) * Math.cos(s);
      r = r * Math.sin(l) * Math.sin(s);
      o *= Math.cos(l);
    } else if ('圆形' == a.shape) {
      var u = Math.random() * Math.PI * 2;
      i *= Math.cos(u);
      r *= Math.sin(u);
      var c = new _e(i, r, (o = 0));
      c.applyMatrix4(this.emitAreaRotateMatrix);
      i = c.x;
      r = c.y;
      o = c.z;
    }
    var h = new mc(1e3 * vc(n, true), this.config);
    this.particleList.push(h);
    h.setPosition(i, r, o);
  }
  onUpdate(e) {
    this.updateEmit(e);
    this.updateParticles(e);
  }
  updateEmit(e) {
    if (this.particleList.length < this.maxCount) {
      this.emitTime += e;
      var t = this.emitRate * this.emitTime;
      if ((t > this.maxCount && (t = this.maxCount - this.particleList.length), t > 1)) {
        for (var n = 1; n <= t; n++) {
          this.emit();
        }
        this.emitTime = 0;
      }
    } else this.emitTime = 0;
  }
  updateParticles(e) {
    var t = this.particleList;
    this.geometry.dispose();
    if (this.instancedMesh) {
      this.remove(this.instancedMesh);
    }
    var n = new Kt();
    n.index = this.planeGeometry.index;
    var a = new Float32Array(t.length);
    n.attributes = this.planeGeometry.attributes;
    this.geometry = n;
    var i;
    var r = new jr(this.planeGeometry, this.particleMaterial, t.length);
    this.add(r);
    this.instancedMesh = r;
    for (var o = 0; o < t.length; o++) {
      (i = t[o]).update(e);
      if (i.isDead) {
        this.removeParticle(i);
        o--;
      } else {
        var s = new Qe();
        s.compose(i.position, i.rotation, i.scale);
        r.setMatrixAt(o, s);
        r.setColorAt(o, i.color);
        a[o] = i.opacity;
      }
    }
    n.setAttribute('opacity', new Rr(a, 1));
  }
  removeParticle(e) {
    this.particleList.splice(this.particleList.indexOf(e), 1);
  }
}
